home *** CD-ROM | disk | FTP | other *** search
/ The Arsenal Files 8 / The Arsenal Files Collection #8 (Arsenal Computer) (1996).ISO / g_quake / cspike10.zip / SPIKES.QC < prev    next >
Text File  |  1996-09-03  |  10KB  |  387 lines

  1.  
  2. //*******************************************************************
  3. // module:     spikes.qc 
  4. // author:     Charlie Zimmerman
  5. // email:     czimmerm@cyberenet.net
  6. // description: Throws a number of random peices of
  7. //        metal in random directions.
  8. //*******************************************************************
  9.  
  10. //************
  11. // EXTERNALS
  12. //************
  13. float() crandom;
  14. void (entity targ, entity inflictor, entity attacker, float damage) T_Damage;
  15.  
  16. //*************
  17. // PROTOTYPES
  18. //*************
  19. void() shrat_touch;
  20. void() dspike_touch;
  21.  
  22. //*******************************************************************
  23. //* throw_a_shrat - throws one peice of metal out
  24. //*******************************************************************
  25. void(vector org,entity own) throw_a_shrat =
  26. {
  27.     // spawn a spike owned by the passed in owner
  28.     newmis = spawn ();
  29.     newmis.classname = "spike";
  30.     newmis.owner = own;
  31.  
  32.     // make it solid and make it bounce
  33.     newmis.movetype = MOVETYPE_BOUNCE;
  34.     newmis.solid = SOLID_BBOX;
  35.  
  36.     // starting angle 
  37.     newmis.angles = '0 0 0';
  38.     
  39.     // function to call when it hits something
  40.     newmis.touch = shrat_touch;
  41.  
  42.     // next time to wake up on own and do something.
  43.     // May wake on own due to touch prior to this.
  44.     if (random() > 0.9) {
  45.         newmis.nextthink = time + random()*90;
  46.     }
  47.     else {
  48.         newmis.nextthink = time + random()*9;
  49.     }
  50.     // what to do on own wake up
  51.     newmis.think = SUB_Remove;
  52.  
  53.     // set size, origin, and model
  54.     setmodel (newmis, "progs/spike.mdl");
  55.     setsize (newmis, VEC_ORIGIN, VEC_ORIGIN);        
  56.     setorigin (newmis, org);
  57.  
  58.     // Start it spinning with random angular velocity
  59.      newmis.avelocity =v_forward*crandom()*600 +
  60.               v_right*crandom()*600 +
  61.               v_up*crandom()*600; 
  62.  
  63.     // Give it random velocity 
  64.     newmis.velocity = v_forward*crandom()*1000 +
  65.               v_right*crandom()*1000 +
  66.               v_up*crandom()*1000; 
  67. };
  68.  
  69. //*******************************************************************
  70. //* throw_shrat - throws number peices of metal out
  71. //*******************************************************************
  72. void(vector org,entity own,float number) throw_shrat =
  73. {
  74.     local float i;
  75.  
  76.     i = 0;
  77.     while (i < number) {
  78.         throw_a_shrat(org,own);
  79.         i = i + 1;
  80.     }
  81.  
  82. };
  83.  
  84. //*********************************************************************
  85. //* shrat_touch - called when metal hits something
  86. //*********************************************************************
  87. void() shrat_touch =
  88. {
  89.     local float dam;
  90.  
  91.     // activate triggers
  92.     if (other.solid == SOLID_TRIGGER)
  93.         return;    // trigger field, do nothing
  94.  
  95.     // vanish if in sky
  96.     if (pointcontents(self.origin) == CONTENT_SKY)
  97.     {
  98.         remove(self);
  99.         return;
  100.     }
  101.     
  102.     // hit something that bleeds
  103.     if (other.takedamage)
  104.     {
  105.         // random damage
  106.         dam = random()*25;
  107.         spawn_touchblood (dam);
  108.         T_Damage (other, self, self.owner, dam);
  109.         remove(self);
  110.     }
  111.     else
  112.     {
  113.         // hit nothing - anounce for richochet
  114.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  115.         
  116.         WriteByte (MSG_BROADCAST, TE_SPIKE);
  117.         WriteCoord (MSG_BROADCAST, self.origin_x);
  118.         WriteCoord (MSG_BROADCAST, self.origin_y);
  119.         WriteCoord (MSG_BROADCAST, self.origin_z);
  120.     }
  121. };
  122.  
  123. //*******************************************************************
  124. //* throw_spike - throws spike in general direction passed in
  125. //*******************************************************************
  126. void(vector org,entity own,vector dir) throw_spike =
  127. {
  128.  
  129.     // throw a spike owned by the owner passed in
  130.     newmis = spawn ();
  131.     newmis.classname = "spike";
  132.     newmis.owner = own;
  133.  
  134.     // make it solid and make it bounce
  135.     newmis.movetype = MOVETYPE_BOUNCE;
  136.     newmis.solid = SOLID_BBOX;
  137.  
  138.     // starting angles
  139.     newmis.angles = '0 0 0';
  140.     
  141.     // function to call when it hits something
  142.     newmis.touch = dspike_touch;
  143.  
  144.     // next time to wake up on own and do something.
  145.     // May wake on own due to touch prior to this.
  146.     if (random() > 0.9) {
  147.         newmis.nextthink = time + random()*90;
  148.     }
  149.     else {
  150.         newmis.nextthink = time + random()*9;
  151.     }
  152.     // what to do on own wake up
  153.     newmis.think = SUB_Remove;
  154.  
  155.     // set size, origin, and model
  156.     setmodel (newmis, "progs/spike.mdl");
  157.     setsize (newmis, VEC_ORIGIN, VEC_ORIGIN);        
  158.     setorigin (newmis, org);
  159.  
  160.     // Start it spinning with random angular velocity
  161.      newmis.avelocity =v_forward*crandom()*600 +
  162.               v_right*crandom()*600 +
  163.               v_up*crandom()*600; 
  164.  
  165.     // Give it random velocity sorta in direction passed in
  166.     // This syntax kills me :)
  167.     newmis.velocity = dir*0.75 + 
  168.             v_forward*crandom()*200 +
  169.             v_right*crandom()*200 +
  170.             v_up*crandom()*200;
  171. };
  172.  
  173. //*******************************************************************
  174. //* fall_spike - drops a spike 
  175. //*******************************************************************
  176. void() fall_spike =
  177. {
  178.     // change a stopped spike to a falling one
  179.     self.movetype = MOVETYPE_BOUNCE;
  180.     newmis.solid = SOLID_BBOX;
  181.     newmis.touch = dspike_touch;
  182.  
  183.     // plan remove at next wake up
  184.     self.think = SUB_Remove;
  185.     self.nextthink = time + 2;
  186.  
  187.     // make it flip when falling
  188.     self.avelocity =v_forward*crandom()*600 +
  189.           v_right*crandom()*600 +
  190.           v_up*crandom()*600; 
  191. };
  192.  
  193. //*******************************************************************
  194. //* stick_spike - sticks a spike where it stops 
  195. //*******************************************************************
  196. void(vector org,vector dir) stick_spike =
  197. {
  198.     local vector facing,neworg;
  199.  
  200.     // spawn a spike owned by the world
  201.     newmis = spawn ();
  202.     newmis.classname = "spike";
  203.     newmis.owner = world;
  204.  
  205.     // make it not solid and stop it
  206.     newmis.movetype = MOVETYPE_NONE;
  207.     newmis.solid = SOLID_NOT;
  208.  
  209.     // set angle of rest based on direction it came in from
  210.     newmis.angles = vectoangles(dir);
  211.  
  212.     // back out spike a little to show more of it
  213.     facing = (-8)*normalize(dir);
  214.     neworg = org + facing;
  215.     
  216.     // next time to wake up on own and do something.
  217.     if (random() > 0.9) {
  218.         newmis.nextthink = time + random()*60;
  219.     }
  220.     else {
  221.         newmis.nextthink = time + random()*9;
  222.     }
  223.     // make spike fall at wake up time
  224.     newmis.think = fall_spike;
  225.  
  226.     setmodel (newmis, "progs/spike.mdl");
  227.     setsize (newmis, VEC_ORIGIN, VEC_ORIGIN);        
  228.     setorigin (newmis, neworg);
  229.  
  230.     // no velocities
  231.     newmis.avelocity = '0 0 0';
  232.     newmis.velocity = '0 0 0';
  233. };
  234.  
  235. //*********************************************************************
  236. //* dspike_touch - deflected spike touches
  237. //*********************************************************************
  238. void() dspike_touch =
  239. {
  240. local float rand;
  241.  
  242.     if (other.solid == SOLID_TRIGGER)
  243.         return;    // trigger field, do nothing
  244.  
  245.     // vanish if it hits sky
  246.     if (pointcontents(self.origin) == CONTENT_SKY)
  247.     {
  248.         remove(self);
  249.         return;
  250.     }
  251.     
  252.     // hit something that bleeds
  253.     if (other.takedamage)
  254.     {
  255.         spawn_touchblood (4);
  256.         T_Damage (other, self, self.owner, 4);
  257.         remove(self);
  258.     }
  259.     else
  260.     {
  261.         // Hello!  I'm here!
  262.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  263.         
  264.         WriteByte (MSG_BROADCAST, TE_SPIKE);
  265.         WriteCoord (MSG_BROADCAST, self.origin_x);
  266.         WriteCoord (MSG_BROADCAST, self.origin_y);
  267.         WriteCoord (MSG_BROADCAST, self.origin_z);
  268.     }
  269. };
  270.  
  271. void() NewGrenadeExplode =
  272. {
  273.     T_RadiusDamage (self, self.owner, 120, world);
  274.  
  275.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  276.     WriteByte (MSG_BROADCAST, TE_EXPLOSION);
  277.     WriteCoord (MSG_BROADCAST, self.origin_x);
  278.     WriteCoord (MSG_BROADCAST, self.origin_y);
  279.     WriteCoord (MSG_BROADCAST, self.origin_z);
  280.     //PATCH*******************************
  281.     // throw shrat from grenades
  282.     //************************************
  283.     throw_shrat(self.origin,self.owner,6); 
  284.     //ENDPATCH****************************
  285.  
  286.     BecomeExplosion ();
  287. };
  288.  
  289. void() new_spike_touch =
  290. {
  291. local float rand;
  292. local float bleeder;
  293.  
  294.     bleeder = 0;
  295.     if (other == self.owner)
  296.         return;
  297.  
  298.     if (other.solid == SOLID_TRIGGER)
  299.         return;    // trigger field, do nothing
  300.  
  301.     if (pointcontents(self.origin) == CONTENT_SKY)
  302.     {
  303.         remove(self);
  304.         return;
  305.     }
  306.     
  307. // hit something that bleeds
  308.     if (other.takedamage)
  309.     {
  310.         spawn_touchblood (9);
  311.         T_Damage (other, self, self.owner, 9);
  312.         bleeder = 1;
  313.     }
  314.     else
  315.     {
  316.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  317.         
  318.         if (self.classname == "wizspike")
  319.             WriteByte (MSG_BROADCAST, TE_WIZSPIKE);
  320.         else if (self.classname == "knightspike")
  321.             WriteByte (MSG_BROADCAST, TE_KNIGHTSPIKE);
  322.         else
  323.             WriteByte (MSG_BROADCAST, TE_SPIKE);
  324.         WriteCoord (MSG_BROADCAST, self.origin_x);
  325.         WriteCoord (MSG_BROADCAST, self.origin_y);
  326.         WriteCoord (MSG_BROADCAST, self.origin_z);
  327.     }
  328.  
  329.     if (bleeder == 0) {
  330.         if (crandom() < 0) {
  331.             throw_spike(self.origin,self.owner,self.velocity); 
  332.         }
  333.         else {
  334.             stick_spike(self.origin,self.velocity);
  335.         }
  336.     }
  337.  
  338.     remove(self);
  339. };
  340.  
  341. void() new_superspike_touch =
  342. {
  343. local float rand;
  344. local float bleeder;
  345.     
  346.     bleeder = 0;
  347.     if (other == self.owner)
  348.         return;
  349.  
  350.     if (other.solid == SOLID_TRIGGER)
  351.         return;    // trigger field, do nothing
  352.  
  353.     if (pointcontents(self.origin) == CONTENT_SKY)
  354.     {
  355.         remove(self);
  356.         return;
  357.     }
  358.     
  359. // hit something that bleeds
  360.     if (other.takedamage)
  361.     {
  362.         spawn_touchblood (18);
  363.         T_Damage (other, self, self.owner, 18);
  364.         bleeder = 1;
  365.     }
  366.     else
  367.     {
  368.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  369.         WriteByte (MSG_BROADCAST, TE_SUPERSPIKE);
  370.         WriteCoord (MSG_BROADCAST, self.origin_x);
  371.         WriteCoord (MSG_BROADCAST, self.origin_y);
  372.         WriteCoord (MSG_BROADCAST, self.origin_z);
  373.     }
  374.  
  375.     if (bleeder == 0) {
  376.         if (crandom() < 0) {
  377.             throw_spike(self.origin,self.owner,self.velocity); 
  378.         }
  379.         else {
  380.             stick_spike(self.origin,self.velocity);
  381.         }
  382.     }
  383.  
  384.     remove(self);
  385.  
  386. };
  387.